package com.selfdriving.activity;

import java.util.ArrayList;
import java.util.List;
import net.tsz.afinal.annotation.view.ViewInject;
import com.selfdriving.R;
import com.selfdriving.adapter.NearbyFriendAdapter;
import com.selfdriving.bean.User;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class MyTravelActivity extends BaseActivity {
	@ViewInject(id = R.id.friend_list)
	ListView friend_list;

	private NearbyFriendAdapter adapter;

	private List<User> users;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.nearby_friend);
		users = new ArrayList<User>();
		for (int i = 0; i < 7; i++) {
			User user = new User();
			users.add(user);
		}
		adapter = new NearbyFriendAdapter(getParent(), users);
		friend_list.setAdapter(adapter);

		friend_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				if (!isLogin()) {
					Intent intent = new Intent(MyTravelActivity.this, RegisterActivity.class);
					startActivity(intent);
				} else {
					Intent intent = new Intent(MyTravelActivity.this,GroupMessageActivity.class);
					startActivity(intent);
				}
			}
		});

		friend_list.setOnItemLongClickListener(new OnItemLongClickListener() {
			@Override
			public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				boolean isEdit = adapter.getEdit();
				adapter.setEdit(!isEdit);
				adapter.notifyDataSetChanged();
				return false;
			}
		});
	}

}
